import React from "react";
import {addTaskExerciseItem, delTaskExerciseItem, setTaskExerciseList} from "../../actions";
import {connect} from "react-redux";

class ReduxClass extends React.Component {

    componentDidMount() {

    }

    updateData () {
        const { setTaskExerciseList } = this.props;
        setTaskExerciseList([{
            a: "a",
            b: "b"
        }])
    }

    render() {
        return (<div>
            <h2>test ReduxClass</h2>
            <button type="button" className="btn btn-primary" onClick={() => { this.updateData(); }}>点击变化</button>
        </div>)
    }
}

function mapStateToProps(state) {
    return {
        taskExerciseList: state.exercise
    }
}

function mapDispatchToProps(dispatch) {
    return {
        setTaskExerciseList: (list) => dispatch(setTaskExerciseList(list)),
        addTaskExerciseItem: item => dispatch(addTaskExerciseItem(item)),
        delTaskExerciseItem: id => dispatch(delTaskExerciseItem(id))
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(ReduxClass);